package com.project.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.project.entity.SysFinance;
import com.project.mapper.SysAccounMapper;
import com.project.mapper.SysFinanceMapper;
import com.project.mapper.SysOrderMapper;
import com.project.service.ISysFinanceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author wangsihan
 * @since 2021-10-08
 */
@Service
public class SysFinanceServiceImpl extends ServiceImpl<SysFinanceMapper, SysFinance> implements ISysFinanceService {

    @Autowired
    SysFinanceMapper financeMapper;

    @Autowired
    SysOrderMapper orderMapper;

    @Autowired
    SysAccounMapper accounMapper;

    /**
     * 根据商户id查询当前财务
     * 根据用户编号，对数据库查询该用户下的所有提现明细集合（集合元素中包含：提
     * 现日期、提现金额、提现时的账户余额
     *
     * @return 财务对象
     */
    @Override
    public SysFinance findStoreId(Integer storeId) {
        //查询出当前商户的所有订单金额
        Double sumMoney = orderMapper.findUserIdBySumMoney(storeId);
        //查询初当前商户的提现金额
        Double withdrawMoney = accounMapper.findStoreIdSumMoney(storeId);

        //当前账户的财务信息
        SysFinance finance = financeMapper.findStoreId(storeId);

        //最后的商户金额，先测试转成int
        finance.setFSummoney((int) (sumMoney - withdrawMoney));


        return finance;
    }


}
